package com.haircut.enums;

import lombok.Getter;

/**
 * 充值状态枚举
 */
@Getter
public enum RechargeStatus {
    INIT(0, "初始化"),
    PAYING(1, "充值中"),
    SUCCESS(2, "充值成功"),
    FAIL(3, "充值失败"),
    REFUNDING(4, "退款中"),
    REFUNDED(5, "已退款"),
    REFUND_FAIL(6, "退款失败");

    private final Integer code;  // 存储到数据库的状态码
    private final String desc;   // 状态描述（用于前端展示或日志）

    RechargeStatus(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据状态码获取枚举
     */
    public static RechargeStatus getByCode(Integer code) {
        for (RechargeStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的充值状态码：" + code);
    }
}